class ListNode(object):
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


class Solution(object):
    def oddEvenList(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if not head or not head.next:
            return head
        node_list = [head, head.next]
        head2 = head.next
        node = head.next.next
        index = 0
        while node:
            node_list[index % 2].next = node
            node_list[index % 2] = node
            node = node.next
            index += 1
        node_list[0].next = head2
        node_list[1].next = None
        return head



